﻿using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    ///  
    /// 安全库存拉动
    /// </summary>
    public class SafetyPullJob : IJobService
    {
        private readonly IPullingRepository pullRepository;
        private readonly IMoveOrderRepository moveOrderRepository;
        private readonly IStockRepository stockRepository;



        public SafetyPullJob(IPullingRepository _pullGroupRepository,
            IMoveOrderRepository _moveOrderRepository,
            IStockRepository _stockRepository)
        {
            this.pullRepository = _pullGroupRepository;
            this.moveOrderRepository = _moveOrderRepository;
            this.stockRepository = _stockRepository;

        }

        public string ExecuteService(string parameter)
        {
            try
            {
                //将异常订单，转成正常订单  华智业务线注释
                //List<WmsMoveHeader> MoveHeaders = pullRepository.GetMoveHeaderWrong0();
                //moveOrderRepository.ChangeSafety(MoveHeaders);

                List<SysLocatePart> pullDetails = pullRepository.SafetyPullList();
                if (pullDetails.Count <= 0)
                {
                    return "无需要生成安全库存的零件列表！";
                }

                moveOrderRepository.CreateSafetyPullOrder("0", pullDetails);
                 
                return "处理完成！";

            }
            catch (Exception ex) 
            {
                LogHelper.Error("处理异常！" + ex);
                return "处理异常！" + ex.Message;
            }
            
        }
    }
}
